// display the radial function Rl(r)
// the data format is in 'r Rl(r)'
// by Asia Sun, Jul. 8, 2022

static int co = 1; // graph color
void primp(TGraph *g); // primp the graph
// get the ymin and ymax of a file with two columns (x, y)
void mm(const string &file, double &mi, double &ma);

void Rl(){
  TLegend *lg = new TLegend(0.7, 0.6, 0.85, 0.85); lg->SetBorderSize(0);
  TGraph *gr = new TGraph("Rl.txt", "%lg %lg");
  primp(gr); lg->AddEntry(gr, "R_{l}(r)");
  TGraph *grr = new TGraph("rRl.txt", "%lg %lg");
  primp(grr); lg->AddEntry(grr, "rR_{l}(r)");
  TGraph *grr2 = new TGraph("rRl2.txt", "%lg %lg");
  primp(grr2); lg->AddEntry(grr2, "|rR_{l}(r)|^{2}");

  // get global y range //
  double mi = 1.e200, ma = -1.e200;
  mm("Rl.txt", mi, ma); mm("rRl.txt", mi, ma); mm("rRl2.txt", mi, ma);
  gr->SetMinimum(mi*1.1); gr->SetMaximum(ma*1.1);

  TCanvas *c = new TCanvas("c", "c", 800, 600);
  gr->Draw();
  grr->Draw("same"); grr2->Draw("same");
  lg->Draw();

  c->Print("Rl.pdf");
} // end main function mom

// primp the graph
void primp(TGraph *g){
  TAxis *ax = g->GetXaxis(); ax->SetTitle("r [fm]"); ax->CenterTitle();
  TAxis *ay = g->GetYaxis(); ay->SetTitle("Rl(r) [fm^{-3/2}]"); ay->CenterTitle();
  co++;
  if(5 == co || 10 == co) co++;
  g->SetLineColor(co); g->SetMarkerColor(co); g->SetLineWidth(2);
} // end function primp

// get the ymin and ymax of a file with two columns (x, y)
void mm(const string &file, double &mi, double &ma){
  ifstream f(file); double x, y;
  while(f >> x >> y){ mi = min(mi, y); ma = max(ma, y); }
} // end main function
